home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n4.arc / WHATITIS.C < prev   
Text File  |  1990-09-13  |  4KB  |  171 lines

  1. /*
  2. WHATITIS.C:    Determine type of PC for .BAT files
  3.  
  4. version:    11-02-89
  5. compiler:    Microsoft QuickC version 2.x
  6. uses:        dos.h, stdio.h, stdlib.h
  7. module type:    .EXE (small model)
  8.  
  9. (C) Copyright 1989 Marty Franz
  10. */
  11.  
  12. /*
  13. This module demonstrates functions that determine what type of
  14. PC, XT, AT, PCjr, etc.    the machine is.
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <dos.h>
  20.  
  21. #define GET_CONFIG_INFO 0xc0        /* service */
  22. #define MISC_INT 0x15            /* interrupt */
  23.  
  24. static union REGS inregs, outregs;
  25. static struct SREGS segs;
  26.  
  27. struct model_entry
  28. {
  29.     char *name;
  30.     int type;         // these were unsigned before
  31.     int submodel;
  32. }
  33. ;
  34.  
  35. #define N_MODELS 12
  36.  
  37. static struct model_entry model_table[N_MODELS] =
  38. {
  39.     "PC",               0xff, -1,
  40.     "PC XT",            0xfe, -1,
  41.     "PC XT",            0xfb, -1,
  42.     "PCjr",             0xfd, -1,
  43.     "AT",               0xfc, 0,
  44.     "AT or Compaq 286", 0xfc, 1,
  45.     "PC XT 286",        0xfc, 2,
  46.     "PC Convertible",   0xf9, -1,
  47.     "PS/2 Model 30",    0xfa, -1,
  48.     "PS/2 Model 50",    0xfc, 4,
  49.     "PS/2 Model 60",    0xfc, 5,
  50.     "PS/2 Model 80",    0xf8, 0
  51. }
  52. ;
  53.  
  54. char *unknown = "Unknown";
  55.  
  56. int pc_type(void)
  57. {
  58.     /*
  59.     This function returns the type of PC we're running on.
  60.     It looks at the ROM ID byte in the BIOS.  We use it to
  61.     check against the work area returned by the get
  62.     configuration call.
  63.     */
  64.  
  65.     unsigned id_byte;
  66.  
  67.     segread(&segs);
  68.     movedata(0xf000, 0xfffe, segs.ds, &id_byte, 1);
  69.     return id_byte & 0x00FF;
  70. }
  71.  
  72. void features(unsigned b)
  73. {
  74.     /*
  75.     Decode the feature byte returned from the get
  76.     configuration service.
  77.     */
  78.  
  79.     puts((b & 0x02) ? "Micro channel" : "PC bus");
  80.     puts((b & 0x04) ? "EBDA allocated" :
  81.       "No EBDA present");
  82.     puts((b & 0x08) ? "External wait supported" :
  83.       "No external wait");
  84.     puts((b & 0x10) ?
  85.               "Keyboard intercept called by Int 0x09" : "");
  86.     puts((b & 0x20) ? "Real-time clock present" :
  87.       "No real-time clock");
  88.     puts((b & 0x40) ? "Second interrupt chip present" :
  89.       "Second interrupt chip not present");
  90.     puts((b & 0x80) ? "DMA channel 3 used by hard disk BIOS" :
  91.       "DMA channel 3 not used by hard disk BIOS");
  92. }
  93.  
  94. char *model_name(unsigned model, unsigned submodel)
  95. {
  96.     /*
  97.     Return a string containing the model name given the model
  98.     and submodel bytes.  A -1 in the structure means we don't
  99.     care what the submodel is, the model byte is sufficient.
  100.     */
  101.  
  102.     int i;
  103.  
  104.     for (i = 0; i < N_MODELS; i++)
  105.     {
  106.         if (model_table[i].type == model &&
  107.           (model_table[i].submodel == -1 ||
  108.           model_table[i].submodel == submodel))
  109.             return (model_table[i].name);
  110.     }
  111.     return unknown;
  112.  
  113. }
  114.  
  115. int pc_config(void)
  116. {
  117.     /*
  118.     This function reads the configuration in the BIOS.  It
  119.     then displays additional information about the PC.
  120.     */
  121.  
  122.     unsigned ds, model;
  123.     char config[9];
  124.  
  125.     segread(&segs);
  126.     ds = segs.ds;
  127.     inregs.h.ah = GET_CONFIG_INFO;
  128.     int86x(MISC_INT, &inregs, &outregs, &segs);
  129.     movedata(segs.es, outregs.x.bx, ds, &config[0], 9);
  130.     if (outregs.x.cflag)
  131.     {
  132.         if (outregs.h.ah == 0x80)
  133.         {
  134.            printf("PC or PCjr detected\n");
  135.         }
  136.         else if (outregs.h.ah == 0x86)
  137.         {
  138.            printf("XT BIOS 11/08/82 or AT BIOS 1/10/84\n");
  139.         }
  140.         else
  141.         {
  142.            printf("Carry flag set, unknown type of PC\n");
  143.         }
  144.     }
  145.     else /* carry not set, data area filled in */
  146.     {
  147.         model = (unsigned)(config[2] & 0x00ff);
  148.         if (model == pc_type() )
  149.         {
  150.             printf("Model: %s\n",
  151.               model_name(model, config[3]));
  152.             printf("Model type: %02x\n", model);
  153.             printf("Submodel type: %d\n", config[3]);
  154.             printf("BIOS revision level: %02d\n",
  155.               config[4]);
  156.             printf("Feature byte: %02x  These are:\n",
  157.               config[5]);
  158.             features(config[5]);
  159.         }
  160.         else
  161.         {
  162.             printf("Unknown type of PC\n");
  163.         }
  164.     }
  165. }
  166.  
  167. int main(int argc, char *argv[])
  168. {
  169.     return pc_config();
  170. }
  171.